package ndquangr.intern.ringtonemaker.listitems;

import java.util.ArrayList;
import java.util.List;

import ndquangr.intern.ringtonemaker.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class MusicInfoAdapter extends ArrayAdapter<String[]>{
	private ArrayList<String> titleItems;
	private ArrayList<String> timeItems;
	
	public MusicInfoAdapter(Context context, int resource, List<String[]> objects) {
		super(context, resource, objects);
		// TODO Auto-generated constructor stub
		titleItems = new ArrayList<String>();
		timeItems = new ArrayList<String>();
		for(int i =0; i< objects.size(); i++) {
			titleItems.add(objects.get(i)[0]);
			timeItems.add(objects.get(i)[1]);
		}  
	}

	@Override
    public View getView(int position, View convertView, ViewGroup parent) {		
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.music_item, null);
        }
        
        String title = titleItems.get(position);
        String duration = timeItems.get(position);
        if (title != null && timeItems != null) {
                TextView tv_title = (TextView) v.findViewById(R.id.tv_musicInfo_title);                    
                TextView tv_duration = (TextView) v.findViewById(R.id.tv_musicInfo_duration);   
                
                tv_title.setText(title);
                tv_duration.setText(duration);                    
        }
        
        return v;
    }
	
}
